package com.house.controller;

import com.house.common.Result;
import com.house.common.PageResult;
import com.house.entity.House;
import com.house.service.HouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.CrossOrigin;

@RestController
@RequestMapping("/house")
@CrossOrigin // 允许跨域访问
public class HouseController {

    @Autowired
    private HouseService houseService;

    @GetMapping("/list")
    public Result<PageResult<House>> getHouseList(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String area,
            @RequestParam(required = false) String type,
            @RequestParam(required = false) Integer priceMin,
            @RequestParam(required = false) Integer priceMax,
            @RequestParam(required = false) Integer status,
            @RequestParam(required = false) String sortField,
            @RequestParam(required = false) String sortOrder) {
        
        PageResult<House> result = houseService.getHouseList(
                page, size, area, type, priceMin, priceMax, status, sortField, sortOrder);
        return Result.success(result);
    }
} 